// Copyright (c) 2008 Matthew Johnson
// Licensed under the MIT License (see license.txt)
package actionml.tracing {
	import actionml.Global;
	
	import flash.text.TextField;
	
	public class TextFieldAppender extends Appender {
		private var _textField:TextField;
		private var _appendTop:Boolean;
		public function TextFieldAppender(o:Object) {
			o ||= {};
			_textField = TextField(Global.document.getChildByName(o["name"] || ""));
			_appendTop = o["appendTop"] || !(o["appendTop"] == false);
			delete o["name"];
			delete o["appendTop"];
			super(o);
		}
		protected override function appendString(s:String) {
			if (_textField) {
				if (_appendTop) {
					_textField.htmlText = s + "\n" + _textField.htmlText;
				} else {
					_textField.htmlText += s + "\n";
				}
			} else {
				throw new Error("Attempt to append text to a TextAppender with no assigned text field.");
			}
		}
	}
}